﻿using System;
using System.Transactions;

namespace NQueries
{
    /// <summary>
    /// Implements the UnitOfWork pattern.
    /// </summary>
    public interface IUnitOfWork : IDisposable
    {
        /// <summary>
        /// The name of the unit of work.
        /// </summary>
        string Name { get; }

        /// <summary>
        /// Returns the current <see cref="IDataContext"/>.
        /// </summary>
        IDataContext DataContext { get; }

        /// <summary>
        /// Saves the changes and commits the unit of work.
        /// </summary>
        /// <returns>The number of objects that have its state changed.</returns>
        int Commit();

        /// <summary>
        /// Creates a new <see cref="DependentTransaction"/> that can be used to join this transaction, e.g. from other threads.
        /// </summary>
        /// <param name="dependentCloneOption"></param>
        /// <returns></returns>
        /// <remarks>Be careful using this, since you dont want any deadlocks on your servers.</remarks>
        DependentTransaction GetDependentTransaction(DependentCloneOption dependentCloneOption);
    }
}